{include file="common/head"/}
<div class="admin-main layui-anim layui-anim-upbit">
    <fieldset class="layui-elem-field layui-field-title">
        <legend>全部{:lang('user')}{:lang('list')}</legend>
    </fieldset> 
    <table class="layui-table" id="list" lay-filter="list"></table>
</div>
<script type="text/html" id="is_lock">
    <input type="checkbox" name="is_lock" value="{{d.id}}" lay-skin="switch" lay-text="正常|禁用" lay-filter="is_lock" {{ d.is_lock == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="state">
    <input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="启动|关闭" lay-filter="state" {{ d.state == 0 ? 'checked' : '' }}>
</script>
<script type="text/html" id="action">
    <a href="{:url('seller/index/index')}?asid={{d.id}}" target="_blank" class="layui-btn layui-btn-xs">登录</a>
    <!-- <div lay-event="channeladd" title="新增通道" class="layui-btn layui-btn-xs">新增通道</div> -->
    <a href="{:url('edit')}?id={{d.id}}" class="layui-btn layui-btn-xs">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>  
<script type="text/html" id="channel"><div class="layui-btn layui-btn-primary layui-btn-xs" lay-event="channellist">码商通道</div></script>  
<script type="text/html" id="order"><div class="layui-btn layui-btn-primary layui-btn-xs" lay-event="orderlist">订单明细</div></script>  
<script type="text/html" id="jiesuan"><div class="layui-btn layui-btn-primary layui-btn-xs" lay-event="jiesuanlist">结算明细</div></script>  
{include file="common/foot"/}
<script>
    layui.use(['table','form'], function() {
        var table = layui.table,form = layui.form, $ = layui.jquery;
        var agentid="{$agentid}";
        var tableIn = table.render({
            id: 'user',
            elem: '#list',
            url: '{:url("children_shop")}',
            method: 'post', 
            page: true,
            cols: [[ 
                {field: 'id', title: '{:lang("id")}', align: 'center',width: 80, fixed: true},
                {field: 'username', title: '姓名',align: 'center', width: 100, fixed: true},
                // {field: 'appid', title: 'APPID',align: 'center', width: 100, fixed: true},
                {field: 'mobile', title: '{:lang("tel")}', width: 130}, 
                {field: 'lv', title: '默认手续费',align: 'center', width: 130}, 
                {field: 'agentname', title: '上级代理',align: 'center', width: 130,templet: '#agentname'}, 
                {field: 'channels', title: '码商通道',align: 'center', width: 100,templet: '#channel'}, 
                {title: '所有订单', align: 'center',width: 100,templet: '#order'}, 
                // {title: '结算明细', align: 'center',width: 100,templet: '#jiesuan'}, 
                // {field: 'is_lock', align: 'center',title: '{:lang("status")}', width: 100,toolbar: '#is_lock'},
                // {field: 'state', align: 'center',title: '交易{:lang("status")}', width: 100,toolbar: '#state'},
                {field: 'addtime', title: '开通时间', width: 160},
                {width: 240, align: 'center', title: '操作', toolbar: '#action', fixed:'right'}
            ]],
            limit: 60,where:{agentid:agentid} //每页默认显示的数量
        });
        form.on('switch(is_lock)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var is_lock = obj.elem.checked===true?0:1;
            $.post('{:url("usersState")}',{'id':id,'is_lock':is_lock},function (res) {
                layer.close(loading);
                if (res.status==1) {
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        });
        form.on('switch(state)', function(obj){
            loading =layer.load(1, {shade: [0.1,'#fff']});
            var id = this.value;
            var state = obj.elem.checked===true?0:1;
            $.post('{:url("userstrade")}',{'id':id,'state':state},function (res) {
                layer.close(loading);
                if (res.status==1) {
                    tableIn.reload();
                }else{
                    layer.msg(res.msg,{time:1000,icon:2});
                    return false;
                }
            })
        }); 
        table.on('tool(list)', function(obj) {
            var data = obj.data;
            if(obj.event === 'del') {
                layer.confirm('您确定要删除该码商吗？', function(index){
                    var loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('usersDel')}",{id:data.id},function(res){
                        layer.close(loading);
                        if(res.code===1){
                            layer.msg(res.msg,{time:1000,icon:1});
                            tableIn.reload();
                        }else{
                            layer.msg('操作失败！',{time:1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
            if(obj.event === 'orderlist') {
                layer.open({
                    type: 2,
                    title:'订单列表',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['80%', '90%'], 
                    content:"{:url('order/ordermin')}?userid="+data.id,
                });    
            }
            if(obj.event === 'channellist') {
                layer.open({
                    type: 2,
                    title:'通道列表',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['80%', '90%'], 
                    content:"{:url('channel/channelmin')}?userid="+data.id,
                });    
            }
            if(obj.event === 'jiesuanlist') {
                layer.open({
                    type: 2,
                    title:'结算明细',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['80%', '90%'], 
                    content:"{:url('order/settlementmin')}?userid="+data.id,
                });    
            }
            if(obj.event === 'channeladd') {
                layer.open({
                    type: 2,
                    title:'新增通道',
                    shade: 0.5,
                    shadeClose: true,
                    area: ['380px', '344px'], 
                    content:"{:url('channel/addchannel')}?userid="+data.id+"&userlv="+data.userlv,
                });    
            } 
        }); 
    });
</script>
</body>
</html>